package com.planegame;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {
    public static MainActivity instance;

    //接受广播！！
    public static float x, y, z;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
        //强制设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        //设置全屏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //显示自定义的SurfaceView视图
        setContentView(new MySurfaceView(this));
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        //注册广播接收器
        IntentFilter filter = new IntentFilter();
        //设置接收广播的类型，这里要和Service里设置的类型匹配，还可以在AndroidManifest.xml文件中注册   
        filter.addAction("whatever.com");
        this.registerReceiver(sensorReceiver, filter);
    }

    private BroadcastReceiver sensorReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context arg0, Intent arg1) {
            // TODO Auto-generated method stub
            String action = arg1.getAction();

            x = arg1.getFloatExtra("xvalue", 0);
            y = arg1.getFloatExtra("yvalue", 0);
            z = arg1.getFloatExtra("zvalue", 0);

        }

    };
}